﻿package mortal.game.view.achievement.item
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.gengine.resource.info.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    import mortal.common.global.*;
    import mortal.common.swfPlayer.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.achievement.data.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.mvc.core.*;

    public class AchievementResultCell extends GSprite
    {
        private var _container:GSprite;
        private var _hideContainer:GSprite;
        private var _bg:GBitmap;
        private var _leftItemBg:GBitmap;
        private var _leftItem:GBitmap;
        private var _titleTxt:GTextFiled;
        private var _line1:ScaleBitmap;
        private var _line2:ScaleBitmap;
        private var _pointBg:GBitmap;
        private var _piontBg:GBitmap;
        private var _numPic:BitmapNumberText;
        private var _progress:BaseProgressBar;
        private var _desTxt:GTextFiled;
        private var _itemArr:Array;
        private var _itemCon:GSprite;
        private var _getBtn:GLoadedButton;
        private var _finishTxt:GTextFiled;
        private var _hidebg:GBitmap;
        private var _title:GBitmap;
        private var _des:GBitmap;
        private var _quesMark:SWFPlayer;
        private var _info:SAchievementType;

        public function AchievementResultCell()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_5:BaseItem = null;
            super.createDisposedChildrenImpl();
            this._container = UIFactory.getUICompoment(GSprite, 0, 0, this);
            this._hideContainer = UIFactory.getUICompoment(GSprite, 0, 0, this);
            this._bg = UIFactory.bitmap(ImagesConst.AchievemenTypeCellBg, 0, 0, this._container);
            this._leftItemBg = UIFactory.bitmap(ImagesConst.AchievementTypeItemBg, 6, 11, this._container);
            this._leftItem = UIFactory.bitmap("", 13, 15, this._container);
            this._titleTxt = UIFactory.gTextField(Language.getString(70803), 0, 5, 300, 30, this._container);
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = TextFormatAlign.CENTER;
            _loc_1.size = 14;
            _loc_1.bold = true;
            this._titleTxt.defaultTextFormat = _loc_1;
            this._piontBg = UIFactory.bitmap(ImagesConst.AchievemenTypePointBg, 241, 9, this._container);
            this._numPic = UIFactory.bitmapNumberText(267, 22, "AchievementNumber.png", 16, 20, -5, this._container, 14);
            this._numPic.align = BitmapNumberText.Mid;
            this._numPic.text = "20";
            this._progress = UIFactory.getUICompoment(BaseProgressBar, 82, 38, this._container);
            this._progress.setBg(ImagesConst.PetLifeBg, true, 145, 14, true);
            this._progress.setProgress(ImagesConst.PetExp, true, 1, 1, 143, 12);
            this._progress.setLabel(BaseProgressBar.ProgressBarTextNumber, 50, -4, 50, 20, GlobalStyle.textFormatHuang);
            this._progress.setValue(50, 100);
            this._line1 = UIFactory.bg(62, 32, 176, 2, this._container, ImagesConst.AchievementTypeLine);
            this._line2 = UIFactory.bg(0, 83, 300, 2, this._container, ImagesConst.AchievementTypeLine);
            this._itemArr = [];
            var _loc_2:int = 0;
            while (_loc_2 < 3)
            {
                
                _loc_5 = UIFactory.getUICompoment(BaseItem);
                _loc_5.setItemStyle(ItemStyleConst.Small);
                _loc_5.isDragAble = false;
                this._itemArr.push(_loc_5);
                _loc_2++;
            }
            this._itemCon = UIFactory.getUICompoment(GSprite, 0, 115, this._container);
            this._desTxt = UIFactory.gTextField("" + Language.getString(70804), 0, 60, 300, 30, this._container);
            var _loc_3:* = GlobalStyle.textFormatHuang2;
            _loc_3.align = TextFormatAlign.CENTER;
            this._desTxt.defaultTextFormat = _loc_3;
            this._finishTxt = UIFactory.gTextField("" + Language.getString(70805), 8, 125, 284, 30, this);
            var _loc_4:* = GlobalStyle.textFormatBai;
            _loc_4.align = TextFormatAlign.CENTER;
            _loc_4.size = 20;
            _loc_4.bold = true;
            this._finishTxt.defaultTextFormat = _loc_4;
            this._finishTxt.setTextFormat(_loc_1);
            this._finishTxt.visible = false;
            this._getBtn = UIFactory.gLoadedButton(ImagesConst.AchievemntGetBtn_upSkin, 125, 185, 53, 27, this._container);
            this._getBtn.configEventListener(MouseEvent.CLICK, this.ongetTotalRewardHd);
            this._hidebg = UIFactory.bitmap(ImagesConst.AchievementHideCellBg, 0, 0, this._hideContainer);
            this._title = UIFactory.bitmap(ImagesConst.AchievementHideTitle, 115, 6, this._hideContainer);
            this._des = UIFactory.bitmap(ImagesConst.AchievementHideCon, 99, 40, this._hideContainer);
            this._quesMark = UIFactory.getUICompoment(SWFPlayer);
            this._quesMark.timeRate = 5;
            this._quesMark.move(146, 157);
            this._quesMark.load("AchievementQuest.swf", ModelType.NormalSwf, null);
            this._hideContainer.addChild(this._quesMark);
            this.showHide(false);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            var _loc_3:BaseItem = null;
            super.disposeImpl(param1);
            this._bg.dispose(param1);
            this._bg = null;
            this._leftItemBg.dispose(param1);
            this._leftItemBg = null;
            this._leftItem.dispose(param1);
            this._leftItem = null;
            this._titleTxt.dispose(param1);
            this._titleTxt = null;
            this._piontBg.dispose(param1);
            this._piontBg = null;
            this._numPic.dispose(param1);
            this._numPic = null;
            this._progress.dispose(param1);
            this._progress = null;
            this._line1.dispose(param1);
            this._line1 = null;
            this._line2.dispose(param1);
            this._line2 = null;
            var _loc_2:int = 0;
            while (_loc_2 < 3)
            {
                
                _loc_3 = this._itemArr[_loc_2];
                _loc_3.dispose(param1);
                _loc_2++;
            }
            this._itemArr = null;
            this._itemCon.dispose(param1);
            this._itemCon = null;
            this._desTxt.dispose(param1);
            this._desTxt = null;
            this._finishTxt.dispose(param1);
            this._finishTxt = null;
            this._getBtn.dispose(param1);
            this._getBtn = null;
            this._hidebg.dispose(param1);
            this._hidebg = null;
            this._title.dispose(param1);
            this._title = null;
            this._des.dispose(param1);
            this._des = null;
            if (this._quesMark)
            {
                this._quesMark.dispose(param1);
            }
            this._quesMark = null;
            this._container.dispose(param1);
            this._container = null;
            this._hideContainer.dispose(param1);
            this._hideContainer = null;
            this._info = null;
            return;
        }// end function

        public function updateTypeCell(param1:SAchievementType) : void
        {
            var _loc_2:SAchievement = null;
            var _loc_3:TAchievement = null;
            this._info = param1;
            this.clear();
            if (this._info == null)
            {
                return;
            }
            if (this._info.curAchievements.length > 0)
            {
                _loc_2 = this._info.curAchievements[0];
                _loc_3 = AchievementConfig.instance.achievementObj[_loc_2.id];
                if (_loc_3)
                {
                    this._titleTxt.text = _loc_3.title;
                    this._numPic.text = "" + _loc_3.achievementPoint;
                    this._desTxt.text = _loc_3.desc;
                    this.updateItems(_loc_3);
                    if (EAchieveStatus._EAchieveStatusOver == this._info.status)
                    {
                        this._progress.setValue(_loc_3.achievementProcess, _loc_3.achievementProcess);
                        this._finishTxt.visible = true;
                        this._itemCon.visible = false;
                    }
                    else
                    {
                        this._progress.setValue(_loc_2.curProcess, _loc_3.achievementProcess);
                        this._finishTxt.visible = false;
                        this._itemCon.visible = true;
                    }
                }
            }
            this.updateBtn();
            return;
        }// end function

        public function showHide(param1:Boolean) : void
        {
            this._container.visible = !param1;
            this._hideContainer.visible = param1;
            if (this._quesMark)
            {
                if (param1)
                {
                    this._quesMark.play();
                }
                else
                {
                    this._quesMark.stop();
                }
            }
            return;
        }// end function

        public function clear() : void
        {
            var _loc_2:BaseItem = null;
            this._titleTxt.text = "";
            this._progress.setValue(0, 100);
            var _loc_1:int = 0;
            while (_loc_1 < 3)
            {
                
                _loc_2 = this._itemArr[_loc_1];
                if (_loc_2 && _loc_2.parent)
                {
                    _loc_2.parent.removeChild(_loc_2);
                }
                _loc_1++;
            }
            return;
        }// end function

        private function updateItems(param1:TAchievement) : void
        {
            var _loc_4:String = null;
            var _loc_5:Array = null;
            var _loc_6:int = 0;
            var _loc_7:String = null;
            var _loc_8:BaseItem = null;
            var _loc_9:Array = null;
            var _loc_10:SPlayerItem = null;
            var _loc_11:ItemData = null;
            this._leftItem.visible = true;
            this._itemCon.visible = true;
            if (this._leftItem.bitmapData)
            {
                this._leftItem.bitmapData = null;
            }
            var _loc_2:* = AchievementConfig.instance.typeObj[param1.typeId];
            if (_loc_2)
            {
                LoaderManager.instance.load(_loc_2.icon + ".jpg", this.onLeftItemLoad, LoaderPriority.LevelB);
            }
            if (param1.rewards == 0)
            {
                this._itemCon.visible = false;
                return;
            }
            var _loc_3:* = ItemConfig.instance.getConfig(int(param1.rewards)) as ItemGiftBagInfo;
            if (_loc_3)
            {
                _loc_4 = _loc_3.itemList1;
                _loc_5 = _loc_4.split("&");
                if (_loc_5 == null || _loc_5.length == 0)
                {
                    return;
                }
                if (_loc_5.length > 3)
                {
                    _loc_5.length = 3;
                }
                _loc_6 = 0;
                while (_loc_6 < 3 && _loc_6 < _loc_5.length)
                {
                    
                    _loc_7 = _loc_5[_loc_6];
                    _loc_8 = this._itemArr[_loc_6];
                    _loc_9 = _loc_7.split("#");
                    _loc_10 = new SPlayerItem();
                    _loc_10.itemCode = _loc_9[1];
                    _loc_10.itemAmount = _loc_9[2];
                    _loc_11 = new ItemData(_loc_10);
                    _loc_8.itemData = _loc_11;
                    _loc_8.x = _loc_6 * 50;
                    this._itemCon.addChild(_loc_8);
                    _loc_6++;
                }
                this._itemCon.x = (this._bg.width - this._itemCon.width) / 2;
            }
            return;
        }// end function

        private function onLeftItemLoad(param1:ImageInfo) : void
        {
            if (this._leftItem && param1.bitmapData)
            {
                this._leftItem.bitmapData = param1.bitmapData;
                this._leftItem.width = 35;
                this._leftItem.height = 35;
            }
            return;
        }// end function

        private function updateBtn() : void
        {
            switch(this._info.status)
            {
                case EAchieveStatus._EAchieveStatusCompelete:
                {
                    this._getBtn.visible = true;
                    this._getBtn.enabled = true;
                    break;
                }
                case EAchieveStatus._EAchieveStatusNotCompelete:
                {
                    this._getBtn.visible = true;
                    this._getBtn.enabled = false;
                    break;
                }
                default:
                {
                    this._getBtn.visible = true;
                    this._getBtn.enabled = false;
                    break;
                    break;
                }
            }
            return;
        }// end function

        private function ongetTotalRewardHd(event:MouseEvent) : void
        {
            if (this._info == null)
            {
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.AchievementGetTypBonus, this._info.type));
            return;
        }// end function

        public function flyIcon(param1:int) : Boolean
        {
            var _loc_2:int = 0;
            var _loc_3:BaseItem = null;
            var _loc_4:Point = null;
            if (this._info == null)
            {
                return false;
            }
            if (this._info.type != param1)
            {
                return false;
            }
            if (this._itemArr && this._itemArr.length > 0)
            {
                _loc_2 = 0;
                while (_loc_2 < this._itemArr.length)
                {
                    
                    _loc_3 = this._itemArr[_loc_2];
                    if (_loc_3.parent == null)
                    {
                    }
                    else
                    {
                        _loc_4 = _loc_3.localToGlobal(GameConst.yellowPoint);
                        FlyToNavbarTool.flyBitmapOriginalToPack(_loc_3.bitmapdata, _loc_4);
                    }
                    _loc_2++;
                }
            }
            return true;
        }// end function

    }
}
